package com.cc8w.exception;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 定义全局异常处理类
 */
@Component  //加了这个注解就加入了spring容器了,就不用在mvc-servlet.xml配置了
public class GlobalExceptionResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        System.out.println(ex);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("ex",ex);
        modelAndView.setViewName("common/error");
        return modelAndView;
    }
}
